package com.yc.cloud.admin.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yc.cloud.admin.service.UmsResourceCategoryService;
import com.yc.cloud.common.basic.dto.BasePageReqDTO;
import com.yc.cloud.entity.UmsResourceCategory;
import com.yc.cloud.mapper.UmsResourceCategoryMapper;
import jakarta.annotation.Resource;
import lombok.val;
import org.springframework.stereotype.Service;


/**
 * <p>
 * 资源分类表 服务实现类
 * </p>
 *
 * @author JackGu
 * @since 2022-09-11
 */
@Service
public class UmsResourceCategoryServiceImpl extends ServiceImpl<UmsResourceCategoryMapper, UmsResourceCategory> implements UmsResourceCategoryService {

    @Resource
    private UmsResourceCategoryMapper umsResourceCategoryMapper;

    @Override
    public IPage<UmsResourceCategory> list(BasePageReqDTO queryParam) {
        val query = new QueryWrapper<UmsResourceCategory>();
        IPage<UmsResourceCategory> page;
        //排序
        if (StrUtil.isNotEmpty(queryParam.getSortBy())) {
            if (BasePageReqDTO.ORDER_DESC.equals(queryParam.getOrder())) {
                query.orderByDesc(UmsResourceCategory.ID);
            } else if (BasePageReqDTO.ORDER_ASC.equals(queryParam.getOrder())) {
                query.orderByAsc(UmsResourceCategory.ID);
            }
        }
        //模糊查询
        if (StrUtil.isNotEmpty(queryParam.getKeyword())) {
            query.and(queryWrapper -> {

            });
        }
        //分页
        if (queryParam.getPage()) {
            page = new Page<>(queryParam.getPageNum(), queryParam.getPageSize(), true);
        } else {
            page = new Page<>(queryParam.getPageNum(), umsResourceCategoryMapper.selectCount(query), true);
        }
        return umsResourceCategoryMapper.selectPage(page, query);
    }
}
